package com.ktjiaoyu.crm.repository;

import com.ktjiaoyu.crm.entity.Plan;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface PlanRepository extends JpaRepository<Plan, Long> {
    /**
     * 通过机会ID查询开发计划
     * @param chcId 机会ID
     * @return list
     */
    public List<Plan> findPlanByChance_ChcId(Long chcId);

    /**
     * 根据计划ID修改计划的执行计划
     * @param plaTodo 执行计划
     * @param plaId 计划ID
     */
    @Query(value = "update sal_plan set pla_todo = :#{#plaTodo} where pla_id = :#{#plaId}", nativeQuery = true)
    @Modifying
    @Transactional(timeout = 10)
    public void updatePlaTodoByPlaId(String plaTodo, Long plaId);

    @Query(value = "update sal_plan set pla_result = :#{#plaResult} where pla_id = :#{#plaId}", nativeQuery = true)
    @Modifying
    @Transactional(timeout = 10)
    public void updatePlaResultByPlaId(String plaResult, Long plaId);
}
